<?php
namespace app\serveradv\service\adv;

use \app\manage\service\ApiBase;
use think\Validate;
/**
 * @Author: 蒋哲
 * @Date:   2017-05-27 16:23:45
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-05-27 18:06:40
 */
class ApiAdv extends ApiBase
{
    protected $addFields   = ["c_id"=>0, "name"=>"", "pic_id"=>'', "description"=>" ", "relative_path"=>"", "absolute_path"=>"",
                              "jump_url"=>"", "add_user_id"=>"", "auditor_id"=>"", "status"=>"1", "order"=>0,
                              "start_time"=>"", "end_time"=>"", "audit_status"=>0];
    protected $advValidate = 'app\serveradv\validate\Adv';
    protected $advLogic    = '\app\serveradv\logic\Adv';
    // 广告位添加
    public function advAdd()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData($this->addFields);
        return $this->stepRun($data,'advAdd','add',$this->advValidate,$this->advLogic);
    }

    // 广告位编辑
    public function advEdit(): array
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $default = array_merge($this->addFields,['id'=>0]);
        $data = $this->issetReceiveData($default);
        return $this->stepRun($data,'advEdit','edit',$this->advValidate,$this->advLogic);
    }

    // 获取某个广告位详情
    public function advInfo()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advInfo','delete',$this->advValidate,$this->advLogic);
    }

    // 删除某个广告位
    public function advDelete()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advDelete','delete',$this->advValidate,$this->advLogic);
    }

    // 启用某个广告位
    public function advEnable()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advEnable','delete',$this->advValidate,$this->advLogic);
    }

    // 禁用某个广告位
    public function advDisable()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'advDisable','delete',$this->advValidate,$this->advLogic);
    }

    // 审核通过某个广告位
    public function advAudit()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'', 'auditor_id'=>'']);
        return $this->stepRun($data,'advAudit','delete',$this->advValidate,$this->advLogic);
    }

    // 审核失败/不通过某个广告位
    public function advAuditFailure()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'', 'auditor_id'=>'']);
        return $this->stepRun($data,'advAuditFailure','delete',$this->advValidate,$this->advLogic);
    }

    // 全部广告位列表获取
    public function advList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['listRows'=>'15', 'page'=>'1']);
        return $this->logic('\app\serveradv\logic\Adv')->advList($data);
    }

    // 某一类广告位列表获取  根据c_id或action进行获取
    public function advClassList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->haveIssetReceiveData(['c_id'=>'', 'listRows'=>'15', 'page'=>'1']);
        return $this->stepRun($data,'advClassList','advClassList',$this->advValidate,$this->advLogic);
    }

    // 不同状态广告位列表获取
    public function advDifferenceStatus()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['audit_status'=>'1', 'listRows'=>'15', 'page'=>'1']);
        return $this->stepRun($data,'advDifferenceStatus','status',$this->advValidate,$this->advLogic);
    }

    //规定上架时间内 正常状态 审核通过的广告位等
    public function advTimeLimit()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->haveIssetReceiveData(['c_id'=>'', 'limit'=>5, 'action'=>'']);
        return $this->stepRun($data,'advTimeLimit','status',$this->advValidate,$this->advLogic);
    }
}
